

function bindvalidator() {
	initvalidator();
	$("#addfrom").validate({onkeyup:false, submitHandler:function (form) {		
 	 	//获取表单提交数据
	 uid=$("uid").val();	
	var ucName = $("#adducName").val();
	
	var ucDeptName = $("#adducDeptName").val();
	
	var ucDeptAddr = $("#adducDeptAddr").val();
	var ucTel = $("#adducTel").val();
	var ucCellphone = $("#adducCellphone").val();
	var ucFax = $("#adducFax").val();
	
	var req = {'currentUserContact.ucName':ucName, "currentUserContact.ucDeptName":ucDeptName, "currentUserContact.ucDeptAddr":ucDeptAddr, "currentUserContact.ucTel":ucTel, "currentUserContact.ucCellphone":ucCellphone, "currentUserContact.ucFax":ucFax};
	var url = "/ag/lwc/add_UserContactAction.action";
	$.post(url, req, function (data) {
	//	alert(data.message);
		if(data.message=="add_UserContact")
		{
			$("#msgdialog").text("增加成功");
			$("#msgdialog").dialog("open");
			setTimeout(function(){window.location.href="/ag/lwc/mainAllContact_UserContactAction.action"},600); 
		}
		else
		{
			$("#msgdialog").text("增加失败");
			$("#msgdialog").dialog("open");
		}

		
		
	});	
	$("#add").dialog("close");
	return false;
}, rules:{"adducTel":{required:true, isTel:true}, "adducName":"required", "adducCellphone":{required:true, isMobile:true},"adducFax":{required:false, isTel:true}}, messages:{"adducName":{required:"*\u5fc5\u987b\u586b\u5199"}, "adducTel":{required:"*\u5fc5\u987b\u586b\u5199", isTel:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801"}, "adducCellphone":{required:"*\u5fc5\u987b\u586b\u5199", isMobile:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u624b\u673a\u53f7\u7801"}, "contact-cfax":{isTel:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u4f20\u771f\u53f7\u7801"}, "adducFax":"\u5fc5\u987b\u4e3a\u6570\u5b57"}});
	
	
	$("#editfrom").validate({onkeyup:false, submitHandler:function (form) {
		
     	 	//获取表单提交数据
		var ucName = $("#editucName").val();
		var ucDeptName = $("#editucDeptName").val();
		var ucDeptAddr = $("#editucDeptAddr").val();
		var ucTel = $("#editucTel").val();
		var ucCellphone = $("#editucCellphone").val();
		var ucFax = $("#editucFax").val();
		 uid=$("#uid").val();uid=$.trim(uid);
		var req = {'currentUserContact.ucId':ucId,'currentUserContact.ucName':ucName, "currentUserContact.ucDeptName":ucDeptName, "currentUserContact.ucDeptAddr":ucDeptAddr, "currentUserContact.ucTel":ucTel, "currentUserContact.ucCellphone":ucCellphone, "currentUserContact.ucFax":ucFax};
		var url = "/ag/lwc/updateContact_UserContactAction.action";
		$.post(url, req, function (data) {
		//	alert(data.message);
			$("#edit").dialog("close");
			if(data.message=="update_UserContact")
			{
				
					$("#msgdialog").text("修改成功");
					$("#msgdialog").dialog("open");
					setTimeout(function(){window.location.href="/ag/lwc/mainAllContact_UserContactAction.action"},600); 		
			}
			else{
				$("#msgdialog").text("修改成功");
				$("#msgdialog").dialog("open");
			}
			
		});
		
		$("#edit").removeClass("blockd");
		$("#edit").addClass("noned");
		$("#edit").dialog("close");
		return false;
	}, rules:{"editucTel":{required:true, isTel:true}, "editucName":"required", "editucCellphone":{required:true, isMobile:true},"editucFax":{required:false, isTel:true}}, messages:{"editucName":{required:"*\u5fc5\u987b\u586b\u5199"}, "editucTel":{required:"*\u5fc5\u987b\u586b\u5199", isTel:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801"}, "editucCellphone":{required:"*\u5fc5\u987b\u586b\u5199", isMobile:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u624b\u673a\u53f7\u7801"}, "editucFax":{isTel:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u4f20\u771f\u53f7\u7801"}}});

}
function initvalidator() {
	jQuery.validator.addMethod("chinese", function (value, element) {
		//alert("chinese validator");
		var chinese = /^[\u4e00-\u9fa5]+$/;
		return this.optional(element) || chinese.test(value);
	}, "\u8bf7\u8f93\u5165\u4e2d\u6587");
	jQuery.validator.addMethod("isMobile", function (value, element) {
		//alert("Mobile validator");
		var length = value.length;
		var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
		return this.optional(element) || (length == 11 && mobile.test(value));
	}, "\u8bf7\u6b63\u786e\u586b\u5199\u60a8\u7684\u624b\u673a\u53f7\u7801"); 
	
	// 电话号码验证      
	jQuery.validator.addMethod("isTel", function (value, element) {
		//alert("Tel validator"); 
		var tel = /^\d{3,4}-?\d{7,9}$/;    //电话号码格式010-12345678  
		return this.optional(element) || (tel.test(value));
	}, "\u8bf7\u6b63\u786e\u586b\u5199\u60a8\u7684\u7535\u8bdd\u53f7\u7801,\u683c\u5f0f010-12345678");
	
	// 联系电话(手机/电话皆可)验证  
	jQuery.validator.addMethod("isPhone", function (value, element) {
		//alert("Phone validator");
		var length = value.length;
		var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
		var tel = /^\d{3,4}-?\d{7,9}$/;
		return this.optional(element) || (tel.test(value) || mobile.test(value));
	}, "\u8bf7\u6b63\u786e\u586b\u5199\u60a8\u7684\u8054\u7cfb\u7535\u8bdd");

}



